<?php
defined ('_JEXEC') or die ('Restricted access');

class modSimCateHelper
{

	var $_pagination = null;
	var $_limit = null;
	var $_limitstart = null;
	
	function __construct(){
	
		//$pageNum = JRequest::getInt("page");
		//$this->_limitstart = ($pageNum) ? ($pageNum - 1)*18 : 0;
		$this->_limitstart = JRequest::getInt("limitstart");
		$this->_limit =  18;
		$mainframe = &JFactory::getApplication();
		$context = JRequest::getCmd('option');
		$view = JRequest::getCmd('view');
		
	}
	
	function getSim()
    {
		$db= &JFactory::getDBO();
        $_limitstart = $this->_limitstart;
		$_limit = $this->_limit;
		$query ="SELECT   a.*,b.provider_name
			     FROM     #__sim a,#__sim_provider b
				 WHERE    a.provider_id = b.provider_id 
				 ORDER BY a.price desc LIMIT $_limitstart,$_limit";
			  
        $db->setQuery($query);
		$rows = $db->LoadObjectList();
		
        return $rows;
    }
	
    function getTotalSim()
    {
		$db= &JFactory::getDBO();
		$query ="SELECT count(*) as total
			     FROM     #__sim a,#__sim_provider b
				 WHERE    a.provider_id = b.provider_id";
			  
        $db->setQuery($query);
		$row = $db->LoadObject();
        return $row;
    }
	
	public function getPagination(){
		$_limitstart = $this->_limitstart;
		$_limit = $this->_limit;
		if (empty($this->_pagination))
		{
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotalSim()->total, $_limitstart, $_limit );
		}
		return $this->_pagination;
	}
	
    function getCategoryName(&$params)
    {
        $db= &JFactory::getDBO();
        $query ="select a.categori_name from #__sim_categories a where a.del_flag=0 and a.categori_id =".$params->get('id');
        $db->setQuery($query);
        $categoriname = $db->loadResult();
        if ($db->getErrorNum())
        {
            echo $db->stderr();
            return false;
        }
        return $categoriname;
    }
    function thousandseperate($value)
    {
        $thausandSepCh = ".";
        $realValue = $value."";
        $result = "";
        $len = strlen($realValue);
        while($len>3){
            $result = $thausandSepCh.substr($realValue,$len-3,3).$result;
            $len=$len-3;
        }
        $result=substr($realValue,0,$len).$result;
        return $result;
    }
}
?>